import requests
import pandas as pd
ldq_key = '37d910e782c83fc25f060611af2cab2a'

def geocode(address, city=None, batch=None, sig=None, output=None, callback=None):
    #地理编码 API 服务地址
    url = 'https://restapi.amap.com/v3/geocode/geo?parameters'
    params = {
        'key': ldq_key,
        'address': address,
        'city': city,
        'batch': batch,
        'sig': sig,
        'output': output, """响应结果的格式可以通过请求参数 output 指定，默认为 JSON 形式。"""
        'callback': callback
    }
#    url的请求方式是get
    response = requests.get(url, params= params)
    data = response.json()
    return data

def regeocode(location, poitype=None, radius=None, extensions=None, batch=None, roadlevel=None, sig=None, output=None, callback=None, homeorcorp=None):
    #逆地理编码 API 服务地址
    url = 'https://restapi.amap.com/v3/geocode/regeo?parameters'
    params = {
        'key': ldq_key,
        'location': location,
        'poitype': poitype,
        'radius': radius,
        'extensions': extensions,
        '''extensions 参数默认取值是 base，也就是返回基本地址信息；
        extensions 参数取值为 all 时会返回基本地址信息、附近 POI 内容、道路信息以及道路交叉口信息。'''
        'batch': batch,
        'roadlevel': roadlevel,
        'homeorcorp': homeorcorp,
        'sig': sig,
        'output': output,
        'callback': callback
    }
    #    url的请求方式是get
    response = requests.get(url, params=params)
    data = response.json()
    return data

def walking(origin, destination, sig=None, output=None, callback=None):
    #步行路径规划API URL
    url = 'https://restapi.amap.com/v3/direction/walking?parameters'
    params = {
        'key': ldq_key,
        'origin': origin,
        'destination': destination,
        'sig': sig,
        'output': output,
        'callback': callback
    }
    response = requests.get(url, params=params)
    data = response.json()
    return data

def transit(origin, destination, city, cityd=None, extensions=None, strategy=None, nightflag=None, date=None, time=None, sig=None, output=None, callback=None):
    #公交路径规划API URL：
    url = 'https://restapi.amap.com/v3/direction/transit/integrated?parameters'
    params = {
        'key': ldq_key,
        'origin': origin,
        'destination': destination,
        'city': city,
        'cityd': cityd,
        'extensions': extensions,
        'strategy': strategy,
        'nightflag':nightflag,
        'date': date,
        'time': time,
        'sig': sig,
        'output': output,
        'callback': callback
    }
    response = requests.get(url, params=params)
    data = response.json()
    return data

def driving(origin, destination, extensions, originid=None, destinationid=None, origintype=None, destinationtype=None, strategy=None, waypoints=None, avoidpolygons=None, province=None, number=None, cartype=None, ferry=None, roadaggregation=None, nosteps=None, sig=None, output=None, callback=None):
    #驾车路径规划API URL：
    url = 'https://restapi.amap.com/v3/direction/driving?parameters'
    params = {
        'key':ldq_key,
        'origin':origin,
        'destination':destination,
        'originid':originid,
        'destinationid':destinationid,
        'origintype':origintype,
        'destinationtype':destinationtype,
        'strategy':strategy,
        'waypoints': waypoints,
        'avoidpolygons':avoidpolygons,
        'province':province,
        'number':number,
        'cartype':cartype,
        'ferry':ferry,
        'roadaggregation':roadaggregation,
        'nosteps': nosteps,
        'sig':sig,
        'output':output,
        'callback':callback,
        'extensions':extensions
    }
    response = requests.get(url, params=params)
    data = response.json()
    return data

def weather(city, extensions=None, output=None):
    #天气查询API服务地址：
    url = "https://restapi.amap.com/v3/weather/weatherInfo?parameters"
    params = {
        'key': ldq_key,
        'city': city,
        'extensions': extensions,
        'output': output
    }
    response = requests.get(url, params=params)
    data = response.json()['lives']
    return data

